package com.zhujy.string;

import java.util.*;

public class LengthOfLongestSubstring {
	public int lengthOfLongestSubstring(String s) {
		if(s == null || s.length() < 1)
			return 0;
		Map<Character,Integer> map = new HashMap<Character,Integer>();
		int j=0;
		int count = 0;
		for(int i = 0;i<s.length();i++) {
			char c = s.charAt(i);
			if(map.containsKey(c) && map.get(c)>=j) {
				j = map.get(c)+1;
			}else {
				count = Math.max(count, i-j+1);
			}
			map.put(s.charAt(i), i);
		}
        return count;
    }
}
